package com.example.demo;

import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;

import org.junit.platform.commons.function.Try;


import com.google.common.io.Files;


import javassist.bytecode.stackmap.BasicBlock.Catch;
import kotlin.io.FilePathComponents;

public class mytest  {
	
	//普通方式调用
	public static void test01(){
		User user = new User();
		
		long startTime = System.currentTimeMillis();
		
		for(int i=0;i< 1000000000;i++) {
			user.getCeshi();
		}
		
		long endTime = System.currentTimeMillis();
		
		
		System.out.println("普通方式执行10亿次："+ (endTime-startTime) + "ms");

	}

	
	//反射方式调用
	public static void test02() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		User user = new User();
		
		Class c1 =  user.getClass();
		
		Method getCeshi = c1.getDeclaredMethod("getCeshi", null);
		
		long startTime = System.currentTimeMillis();
		  
		for(int i=0;i< 1000000000;i++) {
			getCeshi.invoke(user, null);
		}
		
		long endTime = System.currentTimeMillis();
		
		
		System.out.println("反射方式执行10亿次："+ (endTime-startTime) + "ms");

	}
	
	
	//反射方式调用 关闭检测
	public static void test03() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		User user = new User();
		
		Class c1 =  user.getClass();
		
		Method getCeshi = c1.getDeclaredMethod("getCeshi", null);
		
		//关闭检测
		getCeshi.setAccessible(true);
		
		long startTime = System.currentTimeMillis();
		
		for(int i=0;i< 1000000000;i++) {
			getCeshi.invoke(user, null);
		}
		
		long endTime = System.currentTimeMillis();
		
		
		System.out.println("关闭检测方式执行10亿次："+ (endTime-startTime) + "ms");

	}
		
	
	public static void main(String[] args) {
		test01();
		try {
			test02();
		} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			test03();
		} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	

}

